<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
use Home\Model\Orders;
//测试控制器
class OrdersController extends CommonController{
    private $model;
    //构造函数
    public function __init(){
        parent::__init();
        $this->model = new Orders;
    }
    
    //动作
    public function index(){
            //获取订单ID
        if(isset($_SESSION['oid'])){
            $oid = $_SESSION['oid'];
        }else{
           $oid = Q('get.oid');
        }
        $od = Q('get.od');
            //获取订单内容
        $orderData = $this->model->where("oid IN ({$oid})")->find();
        $aa = $this->model->where("oid IN (12)")->get();
        // sp($aa);die;
         //压入订单失效时间
        $time = date('Y-m-d H:i:s',$orderData['time']+3600*24);
        $orderData['offtime'] = $time;
        View::with('orderData',$orderData);
        View::make();
    }
        //合并支付
    public function pay(){
        if(IS_POST){
                //支付的金额
            $pay = Q('post.money');
                //用户ID
            $uid = $_SESSION['uid'];
                //实例化用户
            $userModel = new \Home\Model\User;
                //获取账户余额
            $money = $userModel->where("uid={$uid}")->pluck('money');
                //判断余额是否充足
            if(intval($money) < $pay){
                View::success('余额不足');
                return false;
            }else{
                    //修改余额
                $money = intval($money)-$pay;
                $data = array(
                    'uid' => $uid,
                    'money' => $money
                );
                $userModel->where("uid={$uid}")->save($data);
                    //修改状态
                    //实例化订单表
                $orderModel = new \Home\Model\Orders;
                    //获得订单ID
                $oid = Q('post.oid');
                $paydata = array(
                    'oid' => $oid,
                    'status' => '已付款'
                );
                $orderModel->where("oid={$oid}")->save($paydata);
                View::success('支付成功',U('User/index'));
            }
        }
    }










   
    
}